package com.pm.service.negative.impl;

import java.util.Date;
import java.util.List;

import com.pm.entity.po.file.FileLib;
import com.pm.entity.po.security.User;
import com.pm.entity.po.task.Task;
import com.pm.mapper.file.FileLibMapper;
import com.pm.mapper.task.TaskMapper;
import com.pm.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageInfo;
import com.pm.common.Pages;
import com.pm.entity.po.negative.NegativeChecklist;
import com.pm.entity.vo.NegativeChecklistVo;
import com.pm.mapper.negative.NegativeChecklistMapper;
import com.pm.service.negative.NegativeChecklistService;

@Service
public class NegativeChecklistServiceImlp implements NegativeChecklistService {
    @Autowired
    NegativeChecklistMapper negativeChecklistMapper;
    @Autowired
    FileLibMapper fileLibMapper;
    @Autowired
    TaskMapper taskMapper;
    /**
     * 查负面清单
     * @param negativeChecklist
     * @return
     */
    @Override
    public PageInfo<NegativeChecklistVo> getChecklist(NegativeChecklist negativeChecklist) {
        // 获取当前年
        PageInfo<NegativeChecklistVo> pageInfo = new PageInfo<>(negativeChecklistMapper.getChecklist(negativeChecklist));
        return pageInfo;
    }
    /**
     * 添加负面清单
     * @param negativeChecklist
     * @return
     */
    @Override
    public Integer addChecklist(NegativeChecklist negativeChecklist, User user) {
        FileLib fileLib = new FileLib();
        negativeChecklist.setMonth(DateUtil.getMonth(negativeChecklist.getOccurrenceTime()));
        negativeChecklist.setYear(DateUtil.getYear(negativeChecklist.getOccurrenceTime()));
        Integer negativeChecklist1 = negativeChecklistMapper.addChecklist(negativeChecklist);
        if (negativeChecklist.getFiles().size()!=0) {
            fileLib.setUserId(user.getUserId());
            fileLib.setFiles(negativeChecklist.getFiles());
            fileLib.setAimsId(negativeChecklist.getId());
            fileLib.setType(negativeChecklist.getFileLibType());
            fileLib.setFileAddTime(new Date());
            fileLibMapper.add(fileLib);
        }
        return  negativeChecklist1;
    }
    /**
     * 删除负面清单
     * @param id
     * @return
     */
    @Override
    public Boolean deleteChecklist(Integer id) {
       return negativeChecklistMapper.deleteChecklist(id);
    }

    @Override
    public Boolean updateChecklist(NegativeChecklist negativeChecklist,User user) {
        if (negativeChecklist.getFiles().size()!=0) {
            FileLib fileLib = new FileLib();
            fileLib.setUserId(user.getUserId());
            fileLib.setFiles(negativeChecklist.getFiles());
            fileLib.setAimsId(negativeChecklist.getId());
            fileLib.setType(negativeChecklist.getFileLibType());
            fileLib.setFileAddTime(new Date());
            fileLibMapper.add(fileLib);
        }
        return negativeChecklistMapper.updateChecklist(negativeChecklist);
    }

    @Override
    public NegativeChecklistVo getAllChecklistId(Integer id) {
        NegativeChecklistVo negativeChecklistVo = new NegativeChecklistVo();
        negativeChecklistVo = negativeChecklistMapper.getAllChecklistId(id);
        negativeChecklistVo.setDepartmentName(taskMapper.getDepartmentName(negativeChecklistVo.getTaskId()));
        return negativeChecklistVo;
    }


    @Override
    public Integer add(NegativeChecklist negativeChecklist) {
        return null;
    }

    @Override
    public Integer update(NegativeChecklist negativeChecklist) {
        return null;
    }

    @Override
    public Integer remove(NegativeChecklist negativeChecklist) {
        return null;
    }

    @Override
    public NegativeChecklist load(NegativeChecklist negativeChecklist) {
        return null;
    }

    @Override
    public List<NegativeChecklist> getList(NegativeChecklist negativeChecklist) {
        return null;
    }

    @Override
    public PageInfo<NegativeChecklist> getListByPage(NegativeChecklist negativeChecklist, Pages page) {
        return null;
    }
}
